package com.dlb.andorid;

import android.util.Log;

import com.dlb.andorid.bean.AddressRetrieval;
import com.dlb.andorid.bean.ArgAddAddress;
import com.dlb.andorid.bean.ArgAddOrder;
import com.dlb.andorid.bean.ArgMerchantReg;
import com.dlb.andorid.bean.ArgPayOrder;
import com.dlb.andorid.bean.Car;
import com.dlb.andorid.bean.Coupon;
import com.dlb.andorid.bean.ImgBean;
import com.dlb.andorid.bean.MerchantType;
import com.dlb.andorid.bean.MyAddress;
import com.dlb.andorid.bean.MyFav;
import com.dlb.andorid.bean.Order;
import com.dlb.andorid.bean.OrderBean;
import com.dlb.andorid.bean.OrderInfo;
import com.dlb.andorid.bean.PeripheryShop;
import com.dlb.andorid.bean.ProductBean;
import com.dlb.andorid.bean.ProductDetailBean;
import com.dlb.andorid.bean.Province;
import com.dlb.andorid.bean.SecTypeBean;
import com.dlb.andorid.bean.ServerResult;
import com.dlb.andorid.bean.SuperMarket;
import com.dlb.andorid.bean.SuperMarketType;
import com.dlb.andorid.bean.UserAccount;
import com.dlb.andorid.bean.UserInfo;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.kwan.xframe.mvp.model.BaseModel;
import com.kwan.xframe.mvp.model.api.DataSubscriber;
import com.kwan.xframe.mvp.presenter.IBasePresenter;

import java.util.HashMap;
import java.util.List;

import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable;
import io.reactivex.FlowableEmitter;
import io.reactivex.FlowableOnSubscribe;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Function;

public class XModel extends BaseModel {

	private XApiUtil mXApiUtil;

	public XModel(IBasePresenter iBasePresenter) {
		super(iBasePresenter);
		mXApiUtil = new XApiUtil("http://www.dilinbang.com/", null, null, null);
	}

	public class TransFormJson<T> {
		public Function<String, Flowable<T>> getTransFormer(final java.lang.reflect.Type type) {
			return new Function<String, Flowable<T>>() {
				@Override
				public Flowable<T> apply(@NonNull String s) throws Exception {
					s = s.trim();
					Gson gson = new Gson();
					Log.e("TransFormJson:", s);
					final T msg = gson.fromJson(s, type);
					return Flowable.create(new FlowableOnSubscribe<T>() {
						@Override
						public void subscribe(@NonNull FlowableEmitter<T> e) throws Exception {
							e.onNext(msg);
						}
					}, BackpressureStrategy.BUFFER);
				}
			};
		}
	}

	@Override
	public void onDataNext(int vocational_id, HashMap<String, Object> exData, Object data) {
		if (((XServerMsg) data).getCode() != 0) {
			onDataError(vocational_id, exData, new Throwable(((XServerMsg) data).getMsg()));
		} else {
			super.onDataNext(vocational_id, exData, data);
		}
	}

	public void getBanner() {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_BANNER_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<ImgBean>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getBanner().
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<ImgBean>>>().getTransFormer(type))).subscribeWith(subscriber));
	}

	public void getSecType(long id) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_SECTYPE_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<SecTypeBean>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getSecType(id).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<SecTypeBean>>>().getTransFormer(type))).subscribeWith(subscriber));
	}

	public void getProducts(long id, int page, int num) {
		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_PRODUCTS_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<ProductBean>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getProducts(id, page, num).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<ProductBean>>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getDetail(long id) {
		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_PRODUCT_DETAIL_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<ProductDetailBean>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getProductDetail(id).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<ProductDetailBean>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void addCar(long id, String userId, int num, long typeId, float price) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.ADD_CAR_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<ServerResult>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.addCar(id, userId, num, typeId, price).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<ServerResult>>().getTransFormer(type))).subscribeWith(subscriber));


	}

	public void getCar(String userId) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_CAR_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<Car>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getCar(userId).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<Car>>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getCode(String phone, int ctype) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_CODE_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<String>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getCode(phone, ctype).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<String>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void login(String arg) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.LOGIN_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<UserInfo>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.login(arg).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<UserInfo>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void reg(String arg) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.REG_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<UserInfo>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.reg(arg).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<UserInfo>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void findPwd(String code, String phone, String password) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_PASSWORD_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<String>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.findPwd(code, phone, password).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<String>>().getTransFormer(type))).subscribeWith(subscriber));


	}

	public void getRecommendProducts() {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_RECONMEEND_PRODUCTS_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<ProductBean>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getRecommendProducts().
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<ProductBean>>>().getTransFormer(type))).subscribeWith(subscriber));

	}


	public void searchProducts(String txt, long merchant_id) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_SEARCH_PRODUCTS_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<ProductBean>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.searchProducts(txt, merchant_id).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<ProductBean>>>().getTransFormer(type))).subscribeWith(subscriber));

	}


	public void editCarNum(long id, int num) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.EDIT_CAR_NUM_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<String>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.editCarNum(id, num).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<String>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getJrbk(long merchant_id) {
		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_JRBK_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<ProductBean>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getJrbk(merchant_id).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<ProductBean>>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void addOrder(ArgAddOrder argCars) {
		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.ADD_ORDER_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<Order>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.addOrder(argCars).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<Order>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void payOrder(ArgPayOrder arg) {
		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.PAY_ORDER_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.payOrder(arg).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg>().getTransFormer(type))).subscribeWith(subscriber));

	}


	public void addAddress(ArgAddAddress argCars) {
		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.ADD_ADDRESS_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.addAddress(argCars).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void editAddress(ArgAddAddress argCars) {
		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.EDIT_ADDRESS_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.editAddress(argCars).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getAddressCity() {
		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_ADDRESS_CITYS_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<Province>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getCity().
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<Province>>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getAddress() {
		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_ADDRESS_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<MyAddress>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getAddress().
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<MyAddress>>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void deleteAddress(long address_id) {
		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.DELETE_ADDRESS;
		java.lang.reflect.Type type = new TypeToken<XServerMsg>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.deleteAddress(address_id).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg>().getTransFormer(type))).subscribeWith(subscriber));

	}


	public void getCouponList() {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_COUPON_LIST_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<Coupon>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getCouponList().
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<Coupon>>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getAddressFee(long province_id, long city_id) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_ADDRESS_TOTAL_FEE_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<Float>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getAddressFee(province_id, city_id).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<Float>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getZbhdList(long address_id) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_ZBHD_LIST_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<PeripheryShop>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getZbhdList(address_id).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<PeripheryShop>>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getZbhdInfo(long periphery_shop_id, int page) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_ZBHD_INFO_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<ProductBean>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getZbhdInfo(periphery_shop_id, page).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<ProductBean>>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getAddressRetrieval(long province_id, long city_id, long area_id, String
			keyword) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_ADDRESS_RETRIEVAL_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<AddressRetrieval>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getAddressRetrieval(province_id, city_id, area_id, keyword).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<AddressRetrieval>>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void recharge(int typex, float recharge_money) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_RECHARGE_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<String>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.recharge(typex, recharge_money).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<String>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void exchangePoint(long exchange_num) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_POINT_EXCHANGE_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<String>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.exchangePoint(exchange_num).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<String>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getUserInfo() {
		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_USER_INFO_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<UserInfo>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getUserInfo().
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<UserInfo>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getUserAccount() {
		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_USER_ACCOUNT_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<UserAccount>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getUserAccount().
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<UserAccount>>>().getTransFormer(type))).subscribeWith(subscriber));

	}


	public void getMerchantType() {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_MERCHANT_TYPE;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<MerchantType>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getMerchantType().
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<MerchantType>>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getMerchantReg(ArgMerchantReg arg) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_MERCHANT_REG;
		java.lang.reflect.Type type = new TypeToken<XServerMsg>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getMerchantReg(arg).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getRiderReg(ArgMerchantReg arg) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_RIDER_REG;
		java.lang.reflect.Type type = new TypeToken<XServerMsg>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getRiderReg(arg).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getOrderList(int typex) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_ORDER_LIST;

		subscriber.mExData = new HashMap<>();
		subscriber.mExData.put("type", typex);
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<OrderBean>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getOrderList(typex).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<OrderBean>>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void delOrderList(long orderId, String orderNo, int index) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.DELTE_OEDER_VOCATIONAL_ID;
		subscriber.mExData = new HashMap<>();
		subscriber.mExData.put("index", index);
		java.lang.reflect.Type type = new TypeToken<XServerMsg>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.delOrder(orderId, orderNo).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getOrderInfo(String orderNo) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_ORDER_INFO_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<OrderInfo>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getOrderInfo(orderNo).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<OrderInfo>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void tkOrder(long orderId, String orderNo, int index) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.TK_ORDER_VOCATIONAL_ID;
		subscriber.mExData = new HashMap<>();
		subscriber.mExData.put("index", index);
		java.lang.reflect.Type type = new TypeToken<XServerMsg>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.tkOrder(orderId, orderNo).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void pjOrder(long orderId, String orderNo, int index) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.PJ_ORDER_VOCATIONAL_ID;
		subscriber.mExData = new HashMap<>();
		subscriber.mExData.put("index", index);
		java.lang.reflect.Type type = new TypeToken<XServerMsg>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.pjOrder(orderId, orderNo).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg>().getTransFormer(type))).subscribeWith(subscriber));

	}



	public void addFav(long commodity_id, int typex) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.ADD_FAV_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.addFav(commodity_id, typex).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void delFav(long collection_id) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.DEL_FAV_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.delFav(collection_id).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getFav(int typex) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_FAV_VOCATIONAL_ID;
		subscriber.mExData = new HashMap<>();
		subscriber.mExData.put("tpye", typex);
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<MyFav>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getFav(typex).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<MyFav>>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getSupermarket(long address_id) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_SUPERMARKET_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<SuperMarket>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getSupermarket(address_id).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<SuperMarket>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getSupermarketType(long supermarket_id) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_SUPERMARKETTYPE_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<SuperMarketType>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getSupermarketType(supermarket_id).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<SuperMarketType>>>().getTransFormer(type))).subscribeWith(subscriber));

	}

	public void getSupermarketProduct(long supermarket_id, long supermarket_commodity_type, int page) {

		final DataSubscriber<Object> subscriber = new DataSubscriber<>(this);
		subscriber.vocational_id = XAPI.GET_SUPERMARKETPRODUCT_VOCATIONAL_ID;
		java.lang.reflect.Type type = new TypeToken<XServerMsg<List<ProductBean>>>() {
		}.getType();

		addDisposable(subscriber.vocational_id, mXApiUtil.getSupermarketProduct(supermarket_id, supermarket_commodity_type, page).
				compose(mXApiUtil.wrapTransformer(new TransFormJson<XServerMsg<List<ProductBean>>>().getTransFormer(type))).subscribeWith(subscriber));

	}


}

